package com.syy.writableComparable;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FlowComparableMapper extends Mapper<LongWritable, Text, FlowPhone, Text> {
    private FlowPhone flowPhone = new FlowPhone();
    private Text text = new Text();
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, FlowPhone, Text>.Context context) throws IOException, InterruptedException {
        String s = value.toString();
        String[] split = s.split("\t");
        String phone = split[1];
        Long up = Long.parseLong(split[split.length - 3]);
        Long down = Long.parseLong(split[split.length - 2]);
        Long sum = up + down;

        flowPhone.setDown(down);
        flowPhone.setUp(up);
        flowPhone.setSum(sum);

        text.set(phone);
        context.write(flowPhone, text);
    }
}
